package com.yxs.oauth2.server.mapper;

import com.yxs.oauth2.server.domain.TbPermission;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;
import tk.mybatis.mapper.MyMapper;

import java.util.List;

@Component
public interface TbPermissionMapper extends MyMapper<TbPermission> {

    @Select(
            "SELECT p.*\n"+
                    "      FROM\n"+
                    "          tb_user AS u\n"+
                    "          LEFT JOIN tb_user_role AS ur ON u.id = ur.user_id\n"+
                    "          LEFT JOIN tb_role AS r ON r.id = ur.role_id\n"+
                    "          LEFT JOIN tb_role_permission AS rp ON r.id = rp.role_id\n"+
                    "          LEFT JOIN tb_permission AS p ON p.id = rp.permission_id\n"+
                    "      WHERE\n"+
                    "          u.id =#{userId}")
    List<TbPermission> selectByUserId(Long userId);

}